package com.heima.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.api.user.UserClient;
import com.heima.api.user.dto.UserDto;
import com.heima.order.domain.po.Order;
import com.heima.order.mapper.OrderMapper;
import com.heima.order.service.IOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
@RequiredArgsConstructor
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

//    private final RestTemplate restTemplate;

    private final UserClient userClient;
    @Override
    public Order findById(Long id) {
        // 根据id查询订单
        Order order = getById(id);
        // 远程调用用户服务user_dome
//        UserDto userDto = restTemplate.getForEntity("http://localhost:8080/user/get/" + order.getUserId(), UserDto.class).getBody();
        UserDto userDto = userClient.get(order.getUserId());
        order.setUser(userDto);
        return order;
    }
}
